<?
include("config.php");

$img_pattern = "#(http:\/\/.*\.(jpg|jpeg|gif|png))#";
$img_repl =  '<br><img onmouseover="tooltip.show(this)" onmouseout="tooltip.hide(this)" width="60" name="$1"
			data-user-id="24744541" class="user-profile-link" src="$1"><br>';

$regex_youtube = '#http:\/\/(www\.)?youtube\.com\/watch\?v=([\w-]+).*#i'; 
$youtube_repl = '<br><object width="320" height="240">
  <param name="movie"
         value="http://www.youtube.com/v/$2?version=3&autohide=1&showinfo=0"></param>
  <param name="allowScriptAccess" value="always"></param>
  <embed wmode="opaque" src="http://www.youtube.com/v/$2?version=3&autohide=1&showinfo=0"
         type="application/x-shockwave-flash"
         allowscriptaccess="always"
         width="320" height="240"></embed>
</object><br>';

$regex_daily = '#http:\/\/(www\.)?dailymotion\.com\/video\/(.*)(_.*)*#i';
$daily_repl = '<br><object width="320" height="240">
<param name="movie" value="http://www.dailymotion.com/swf/video/$2?theme=none"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<param name="wmode" value="opaque"></param>
<embed wmode="opaque" type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/$2?theme=none" width="320" height="240" wmode="direct" allowfullscreen="true" allowscriptaccess="always"></embed></object><br>';

$link = mysql_connect ('localhost', DB_USER_NAME, DB_PASSWORD) or die ("Cannot join database");
mysql_select_db (DB_NAME);


$requete = "SELECT * FROM user WHERE pseudo='" . $_GET['user'] . "'";
$result = mysql_query ($requete);

if(mysql_num_rows($result) == 0)
{
	echo "This user doesn't exist<br>";
}
else{

	if(isset($_GET['action']))
	{
		$requete = "DELETE FROM stream WHERE id_stream='" . $_GET['action'] . "'";
		$result = mysql_query ($requete);	
	}


	$requete = "SELECT * FROM stream WHERE user='" . $_GET['user'] . "' ORDER BY date DESC LIMIT 0, 10";
	$result = mysql_query ($requete);

	if(mysql_num_rows($result) == 0)
	{
		echo "This user haven't posted any stream<br>";
	}
	else
	{
		echo '<div class=stream>';
		while($row = mysql_fetch_array($result))
		{
		
			echo '<div class=msg msg-id="1" user-id="24744541">';

			// Inclusion de l'image
			echo '<div class=user-image>
		 		 <img width="48" height="48" data-user-id="24744541" class="user-profile-link" src="avatar/' . $row['user'] . '.jpg">
	 			</div>';

			echo '<div class="msg-content">';

			echo '<div class="msg-row">';
			echo $row['user'];
	 		echo '</div>';

			echo '<div class="msg-row">';
			echo $row['resume'];
		 	echo '</div>';

			echo '<div class="msg-row">';
			$message = preg_replace($img_pattern, $img_repl, $row['message']);
			$message1 = preg_replace($regex_youtube, $youtube_repl, $message);
			$message2 = preg_replace($regex_daily, $daily_repl, $message1);
			echo $message2;
	 		echo '</div>';

			echo '<div class="msg-row">';
			echo  'Added: ' . date('d/n/Y', $row['date']) . ' at ' . date('h:i:s', $row['date']); 
			if(isset($_SESSION['pseudo']))
			{
				if($_SESSION['pseudo'] == "admin")
				{
					echo " <a href=\"index.php?user=" . $_GET['user'] . "&action=" . $row['id_stream'] . "\">Delete this stream </a>";
				}
			} 
		 	echo '</div>';

			echo '</div>';// Fin du div msg-content

			echo '</div>'; // Fin du div msgs
			echo '<br>';
		}
		echo '</div>';
	
	}

}





?>
